<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>  
    <link rel="stylesheet" href="../css/pintuer.css">
    <link rel="stylesheet" href="../css/admin.css">
    <script src="../js/jquery.js"></script>
    <script src="../js/pintuer.js"></script>  
    <script src="../js/jqPaginator.min.js"></script>  
</head>
<body>
<form method="post" action="">
  <div class="panel admin-panel">
    <div class="panel-head"><strong class="icon-reorder"> 热搜列表</strong></div>
    <div class="padding border-bottom">
      <ul class="search" >
      	 <li> <a class="button border-main icon-plus-square-o" href="${ctx }/serve/topSearchForm.jsp"> 添加内容</a> </li>
         <li style="float: right;padding-right: 3%;">
          <input type="text" placeholder="请输入热搜名称"  class="input" style="width:250px; line-height:17px;display:inline-block"  id="name"/>
          <a href="javascript:void(0)" class="button border-main icon-search" id="submit"> 搜索</a>
        </li>
      </ul>
    </div>
    <table class="table table-hover text-center" >
      <tr>
      	<th>ID</th>
        <th>名称</th>
		<th>描述</th>		
        <th>状态</th>
        <th>创建时间</th>
        <th width="250">操作</th>       
      </tr>      
       <tbody id="content">
       		
       </tbody>
      <tr>
        <td colspan="7">
        	<div class="pagelist">
                <ul class="pagination" id="pagination">
				</ul>
				<input id="totalCount" type="hidden" value="${pageUtil.getTotalCount() }"/>
			    <input id="pageSize" type="hidden" value="10"/>
				<input id="currentPage" type="hidden" value="${pageUtil.getCurPage() }"/>
				<select id="rank" style="padding:5px 15px; border:1px solid #ddd;">
					<option value="desc">降序</option>
					<option value="asc">升序</option>
				</select>
         	</div>
         </td>
      </tr>
    </table>
  </div>
</form>
<script type="text/javascript">

//单个删除
function del(id){
	if(confirm("您确定要删除热搜吗?")){
		window.location.href="${ctx }/topSearch/delete?id="+id;
	}
}
</script>
 <script type="text/javascript">
		  $(function(){
				function page(){
					var totalCount=parseInt($("#totalCount").val());
					var pageSize=parseInt($("#pageSize").val());
					var currentPage=parseInt($("#currentPage").val());
					$('#pagination').jqPaginator({
						totalCounts: totalCount,
			            currentPage: currentPage,
			            pageSize: pageSize,
			            visiblePages: 7,
						first: '<a href="javascript:void(0);">首页</a>',
						prev: '<a href="javascript:void(0);"><i class="arrow arrow2"></i>上一页</a>',
						next: '<a href="javascript:void(0);">下一页<i class="arrow arrow3"></i></a>',
						last: '<a href="javascript:void(0);">末页</a>',
						page: '<a href="javascript:void(0);">{{page}}</a>',
						onPageChange: function (num) {
							
							var rank=$("#rank").val();
							var name=$("#name").val();
							var url="${ctx }/topSearch/findAll";
							$.post(url,{"curPage":num,"rank":rank,"name":name},callback,"json");
							function callback(data){
								
								   var json=eval(data);
								   var content=json.content;
								   $("#content").html("");
								   for(var i=0;i<content.length;i++){
									   
									   if(content[i].status==1){
										   content[i].status="<font color='green'>正常</font>";
									   }else if(content[i].status==0){
									   	   content[i].status="<font color='red'>停用</font>";
									   }
									   
									   var rowContent = "<tr>"
										    + "<td>"
		                                    + content[i].id
		                                    + "</td>"
		                                    + "<td>"
		                                    + content[i].name
		                                    + "</td>"
											 + "<td>"
		                                    + content[i].describe
		                                    + "</td>"
		                                    + "<td>"
		                                    + content[i].status
		                                    + "</td>"
		                                    + "<td>"
		                                    + content[i].createDateFormat
		                                    + "</td>"
		                                    + "<td><div class='button-group' ><a class='button border-main' href='${ctx }/topSearch/findById?id="+content[i].id+"'><span class='icon-edit'></span> 修改</a><a class='button border-red' href='javascript:void(0);' onclick='return del("+content[i].id+")''><span class='icon-trash-o'></span> 删除</a> </div>"
		                                    + "</td>"
		                                    + "</tr>";
									   $("#content").append(rowContent);
 
								   }
							}			
						}
					});
				}
				
				$("#submit").click(function(){
					page();
				});
				
				page(); 
			  
				$("#rank").change(function(){
					page();
				});
			}); 
  </script>
</body></html>